export enum productTypeEnum {
  Nomal,
  Aged,
  Sulfuras,
  Backstage,
}

export default class Product{
  private type: number;
  private sellIn: number;
  private quality: number;
  constructor(type: number, sellIn: number, quality: number) {
    if(quality > 50 || quality < 0) {
      throw new RangeError
    }
    this.type = type
    this.sellIn = sellIn;
    this.quality = quality;
  }
  public getSellIn() {
    return this.sellIn
  }
  public getQuality() {
    return this.quality
  }
  private nomalCount () {
    const {sellIn, quality } = this
    this.sellIn = sellIn - 1 

    if (sellIn > 0 ){
      if(quality > 0 ) {
        this.quality = quality -1
      } else {
        this.quality = 0
      }
    } else {
      if (quality > 1) {
        this.quality = quality - 2
      } else {
        this.quality = 0
      }
    }
  }
  private agedCount() {
    const {sellIn, quality } = this
    this.sellIn = sellIn - 1 

    if (sellIn > 0 ){
      if(quality < 50 ) {
        this.quality = quality + 1
      } else {
        this.quality = 50
      }
    } else {
      if (quality < 49 ) {
        this.quality = quality + 2
      } else {
        this.quality = 50
      }
    }
  }
  private backStageCount() {
    const {sellIn, quality } = this
    this.sellIn = sellIn - 1 

    if (sellIn > 10 ){
      if(quality < 50 ) {
        this.quality = quality + 1
      } else {
        this.quality = 50
      }
    } else if ( sellIn > 4) {
      if ( quality < 49 ) {
        this.quality = quality + 2
      } else {
        this.quality = 50
      }
    } else if ( sellIn > -1 ){
      if ( quality < 48 ) {
        this.quality = quality + 3
      } else {
        this.quality = 50
      }
    } else {
      this.quality = 0
    }
  }
  public updateByOneDay () {
    const { type } = this
    switch (type) {
      case productTypeEnum.Nomal: {
        this.nomalCount()
        break;
      }
      case productTypeEnum.Aged: {
        this.agedCount();
        break;
      }
      case productTypeEnum.Backstage: {
        this.backStageCount()
      }
      default: {}
    }
  }
  
  
}

